home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / sysmacros_md.h < prev    next >
C/C++ Source or Header  |  1998-09-15  |  3KB  |  117 lines

  1. /*
  2.  * @(#)sysmacros_md.h    1.17 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. #ifndef _WIN32_SYSMACROS_MD_H_
  16. #define _WIN32_SYSMACROS_MD_H_
  17.  
  18. #define sysMalloc    malloc
  19. #define sysFree        free
  20. #define sysCalloc     calloc
  21. #define sysRealloc    realloc
  22.  
  23. /* A macro for sneaking into a sys_mon_t to get the owner sys_thread_t */
  24. #define sysMonitorOwner(mid)   ((mid)->monitor_owner)
  25.  
  26. #ifdef DEBUG
  27. #define sysAssert(expression) {        \
  28.     if (!(expression)) {        \
  29.     DumpThreads();            \
  30.     panic("\"%s\", line %d: assertion failure\n", __FILE__, __LINE__); \
  31.     }                    \
  32. }
  33. #else
  34. #define sysAssert(expression) 0
  35. #endif
  36.  
  37. /*
  38.  * Check whether an exception occurred.  This also gives us the oppor-
  39.  * tunity to use the already-required exception check as a trap for other
  40.  * system-specific conditions.
  41.  */
  42. #define sysCheckException(ee) \
  43.     if (!exceptionOccurred(ee)) { \
  44.        continue; \
  45.     }
  46.  
  47. /*
  48.  * Case insensitive compare of ASCII strings
  49.  */
  50. #define sysStricmp(a, b)        stricmp(a, b)
  51.  
  52. #define sysIsAbsolute(s) \
  53.     (*(s) == '/' || *(s) == '\\' \
  54.      || (isalpha(*(s)) && *((s)+1) == ':' \
  55.          && (*((s)+2) == '\\' || *((s)+2) == '/')))
  56.  
  57. #define sysRead(fd, buf, n)    read(fd, buf, n)
  58. #define sysWrite(fd, buf, n)    write(fd, buf, n)
  59. #define sysClose(fd)        close(fd)
  60. #define sysReadDir(dirp)    readdir(dirp)
  61. #define sysCloseDir(dirp)    closedir(dirp)
  62. #define sysSeek(fd,where,whence) lseek(fd,where,whence)
  63.  
  64. /*
  65.  * Set up thread-local storage for second order monitor cache.  The
  66.  * number of words of thread-local storage must be a power of 2!
  67.  */
  68. #define SYS_TLS_MONCACHE 8 /* must be power of 2 */
  69. #define sysCurrentCacheKey(tid) (tid->cacheKey)
  70. #define sysLocalMonCache(tid, hash) (tid->monitorCache[hash])
  71.  
  72.  
  73. #define sysMemoryFlush()  __asm { lock xor    DWORD PTR 0[esp], 0 }
  74.  
  75. /*
  76.  * Intel doesn't seem to support a weak consistency model for MP
  77.  * so we define this to do nothing.
  78.  */
  79. #define sysStoreBarrier() 0
  80.  
  81. /*
  82.  * Simple, fast recursive lock for the monitor cache.
  83.  */
  84. #include "mutex_md.h"
  85.  
  86. typedef struct {
  87.     mutex_t mutex;
  88.     long entry_count;
  89.     unsigned long owner;
  90. } cache_lock_t;
  91.  
  92. /*
  93.  * We do leave the mutex locked across the whole cache lock to avoid
  94.  * the extra unlock and lock that a smaller critical region would entail.
  95.  */
  96. extern cache_lock_t _moncache_lock;
  97. #define sysCacheLockInit() {   mutexInit(&_moncache_lock.mutex);    \
  98.                    _moncache_lock.entry_count = 0;        \
  99.                    _moncache_lock.owner = 0;        \
  100.                }
  101. #define sysCacheLock()     {   mutexLock(&_moncache_lock.mutex);    \
  102.                    sysAssert(_moncache_lock.entry_count >= 0);\
  103.                    if (_moncache_lock.entry_count++ == 0) {    \
  104.                   _moncache_lock.owner = GetCurrentThreadId();\
  105.                    }                    \
  106.                }
  107. /* Should not need locking: */
  108. #define sysCacheLocked()   (_moncache_lock.owner == GetCurrentThreadId())
  109. #define sysCacheUnlock()   {   sysAssert(_moncache_lock.entry_count > 0);\
  110.                    if (--_moncache_lock.entry_count == 0) {    \
  111.                   _moncache_lock.owner = 0;        \
  112.                    }                    \
  113.                    mutexUnlock(&_moncache_lock.mutex);    \
  114.                }
  115.  
  116. #endif /*_WIN32_SYSMACROS_MD_H_*/
  117.